/*
 * GoToLineDialog.java
 * 
 * last update: 14.01.2010 by Stefan Saru
 * 
 * author:	Felix(felix@ulise.cs.pub.ro)
 *
 * Obs: N/A
 */

package ide;

import javax.swing.*;
import javax.swing.text.*;
import javax.swing.border.*;

import java.awt.*;
import java.awt.event.*;



@SuppressWarnings("serial")
public class GoToLineDialog extends JDialog {
	public JTextField label = new JTextField();


	boolean isValid = false;

	public String getLineNumber() {
		try {
			return ((AbstractDocument)label.getDocument()).getText(0, ((AbstractDocument)label.getDocument()).getLength());
		} catch(Exception e) {System.out.println("Unexpected Internal error: BadLocation exception in GoToLineDialog");
		return "";}
	}


	VeriSimFrame god;

	public GoToLineDialog(VeriSimFrame god) {
		super(god, "Go to line number:", true);
		this.god = god;




		JPanel bp = new JPanel(new BorderLayout());
		JButton ok = new JButton("Ok");
		JButton cancel = new JButton("Cancel");

		ok.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				isValid = true;
				setVisible(false);
				//theProject.jumpToLine();
			} 
		});

		cancel.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				isValid = true;
				setVisible(false);
				//hide
			} 
		});


		getContentPane().setLayout(new BorderLayout());
		getContentPane().add(label, BorderLayout.NORTH);

		bp.add(ok, BorderLayout.EAST);
		bp.add(cancel, BorderLayout.WEST);

		getContentPane().add(bp, BorderLayout.SOUTH);
		pack();
		centerDialog();
	}

	protected void centerDialog() {
		Dimension screenSize = this.getToolkit().getScreenSize();
		Dimension size = this.getSize();
		screenSize.height = screenSize.height/2;
		screenSize.width = screenSize.width/2;
		size.height = size.height/2;
		size.width = size.width/2;
		int y = screenSize.height - size.height;
		int x = screenSize.width - size.width;
		this.setLocation(x,y);
	} 
}
